package cn.itcast;


import cn.itcast.dao.BookDao;
import cn.itcast.domain.Book;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class mybatis_test {

    public static void main(String[] args) throws IOException {
        InputStream in = Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(in);
        SqlSession session = build.openSession();
        BookDao mapper = session.getMapper(BookDao.class);
        List<Book> all = mapper.findAll();
        for (Book book : all) {
            System.out.println(book.getKind().getKname());
            System.out.println(book.getAuthor());
            System.out.println(book.getBookName());
            System.out.println(book.getPrice());
            System.out.println("------------------------------");
        }
    }
}
